<template>
    <div v-show="visible">
        <div class="grid_cont">
            <div style="display:flex;">
                <div style="width: 3px;height: 18px;background-color: rgba(204,53,47,1);"></div>
                <div style="margin-left:10px;font-size: 16px;line-height: 16px;">提交信息</div>
            </div>
            <div
                style="width: 100%;height: 1px;background-color:rgba(245,245,245,1);margin-top:16px;margin-bottom:30px;">
            </div>
            <el-form :model="formParams" style="margin-left:14px;text-align:right;" label-width="112px">
                <el-row>
                    <el-col :span="8" style="min-width:300px;">
                        <el-form-item required label="姓名：" prop="residentName">
                            <el-input disabled v-model="formParams.residentName" style="width: 280px;" />
                        </el-form-item>
                    </el-col>
                    <el-form-item label="性别：" prop="sex">
                        <el-radio-group disabled v-model="formParams.sex">
                            <el-radio label='1'>男</el-radio>
                            <el-radio label='2'>女</el-radio>
                        </el-radio-group>
                    </el-form-item>
                </el-row>
                <el-row>
                    <el-col :span="8" style="min-width:300px;">
                        <el-form-item required label="身份证号：" prop="idNumber">
                            <el-input disabled v-model="formParams.idNumber" style="width: 280px;" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="8" style="min-width:300px;">
                        <el-form-item required label="出生日期：" prop="birthDate">
                            <el-date-picker disabled v-model="formParams.birthDate" format="YYYY-MM-DD" type="date"
                                placeholder="选择日期" style="width: 280px;" />
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="8" style="min-width:300px;">
                        <el-form-item required label="类型：" prop="type">
                            <el-input disabled v-model="formParams.type" style="width: 280px;" />
                        </el-form-item>

                    </el-col>
                    <el-col :span="8" style="min-width:300px;">
                        <el-form-item required label="联系电话：" prop="phone">
                            <el-input disabled v-model="formParams.phone" style="width: 280px;" />
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="8" style="min-width:300px;">
                        <el-form-item required v-if="formParams.type !== '流动居民'" label="户籍地：" prop="address">
                            <el-input disabled v-model="formParams.address" style="width: 280px;" />
                        </el-form-item>

                    </el-col>
                    <el-col :span="8" style="min-width:300px;">
                        <el-form-item label="民族：" v-if="formParams.type !== '流动居民'" prop="nation">
                            <el-input disabled v-model="formParams.nation" style="width: 280px;" />
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="8" style="min-width:300px;">
                        <el-form-item required label="是否户主：" v-if="formParams.type !== '流动居民'" prop="isHolder"
                            style="line-height: 40px;">
                            <el-radio-group v-model="formParams.isHolder" disabled>
                                <el-radio label='1'>是</el-radio>
                                <el-radio label='0'>否</el-radio>
                            </el-radio-group>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8" style="min-width:300px;">
                        <el-form-item label="年收入(万)：" v-if="formParams.type !== '流动居民'" prop="income">
                            <el-input disabled v-model="formParams.income" style="width: 280px;" />
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="8" style="min-width:300px;">
                        <el-form-item required label="与户主关系："
                            v-if="formParams.type !== '流动居民' && formParams.isHolder === '0'" prop="">
                            <el-input disabled v-model="formParams.relationship" style="width: 280px;" />
                        </el-form-item>
                        <el-form-item label="选择户主：" v-if="formParams.type !== '流动居民' && formParams.isHolder === '0'"
                            prop="holderId">
                            <el-input disabled placeholder="暂无" v-model="formParams.holderId" style="width: 280px;" />
                        </el-form-item>
                        <el-form-item required label="选择房屋：" v-if="formParams.type !== '流动居民'" prop="houseNumber">
                            <el-input disabled v-model="formParams.houseNumber" style="width: 280px;" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="8" style="min-width:300px;">

                        <el-form-item label="照片：" v-if="formParams.type !== '流动居民'" prop="area">
                            <UploadImg v-if="formParams.photo" disabled v-model="formParams.photo" :limit="1" />
                            <el-upload v-else disabled class="avatar-uploader" style="position:relative">
                                <el-icon disabled class="avatar-uploader-icon" />
                                <div style="position:absolute;cursor: not-allowed;user-select: none;color: #999;">暂无照片
                                </div>

                            </el-upload>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <div style="display:flex;margin-bottom:20px;">
                <div style="width: 3px;height: 18px;background-color: rgba(204,53,47,1);"></div>
                <div style="margin-left:10px;font-size: 16px;line-height: 16px;">居民标签</div>
            </div>
            <el-form :model="formData">
                <el-row>
                    <el-col :span="16">
                        <el-form-item v-model="optionlabel" style="margin-left:14px;"
                            :rules="[{ required: true, message: '标签类型不能为空！' }]">
                            <div v-for="(item, index) in optionlabel" class="identity_style" :key="item.value"
                                :class="{ selected: item.selected }" :title="item.label" @click="colorbtn(index)">
                                {{ item.label }}</div>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <div style="display:flex;margin-bottom:20px;">
                <div style="width: 3px;height: 18px;background-color: rgba(204,53,47,1);"></div>
                <div style="margin-left:10px;font-size: 16px;line-height: 16px;">审核</div>
            </div>
            <el-form :model="formData">
                <el-form-item label="审核结果：" style="margin-left:14px;">
                    <el-radio-group v-model="formData.result">
                        <el-radio label='true'>通过</el-radio>
                        <el-radio label='false'>驳回</el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item required prop="situation" v-if="formData.result === 'false'" label="驳回说明：" :rules="[
                    { required: true, message: '驳回说明不能为空！' }]" style="margin-left: 4px;">
                    <el-input v-model="formData.situation" maxlength="20" style="width: 320px;" placeholder=""
                        show-word-limit type="textarea" />
                </el-form-item>
            </el-form>
        </div>
        <div class="grid_cont2">
            <el-button class="grid_btn" @click="gridCancel"
                style="background-color: rgba(255, 255, 255, 1);border: 1px solid rgba(187, 187, 187, 1);color: rgba(142, 142, 142, 1);">返回</el-button>
            <el-button class="grid_btn" @click="gridSure"
                style="background-color:#FF9900;border: 1px solid #FF9900;color:#fff;">审核</el-button>
        </div>
    </div>
</template>

<script lang="ts" setup>
import * as getgridApi from '@/api/countryside/gridmanagement/index'
import globalApi from '@/api/spb/global'
const formParams = reactive({
    residentName: '',
    idNumber: '',
    type: '',
    birthDate: '',
    address: '',
    optionplace: [],
    phone: '',
    houseNumber: '',
    nation: '',
    isHolder: '1',
    holderId: '',
    income: '',
    relationship: '',
    sex: '1',
    photo: '',
    title: ''
})
const optionlabel = ref([])
const formData = reactive({
    result: 'true',
    situation: '',
})
const visible = ref(false)
const props = defineProps({
    examineShow: {
        type: Boolean,
        default: false
    },
    editData: {
        type: Object
    }
})

const emit = defineEmits(['getexamineShow', 'geteditData'])
watch(() => props.examineShow, (val) => {
    visible.value = val
}, { immediate: true })
watch(() => props.editData, (val) => {
    optionlabel.value = []
    if (val) {
        formParams.residentName = val.residentName
        formParams.idNumber = val.idNumber
        formParams.type = val.residentType
        formParams.birthDate = String(val.birthDate)
        formParams.address = val.address
        formParams.phone = val.telephone
        formParams.houseNumber = val.houseNumber
        formParams.nation = val.nation
        formParams.isHolder = val.isHolder
        formParams.holderId = val.holderId
        formParams.income = val.income
        formParams.relationship = val.relationship
        formParams.sex = val.sex
        formParams.photo = val.photo
        optionlabel.value = val.optionlabel
    }
}, { immediate: true })
/** 获取居民标签列表 */
const getresidentLabel = () => {
    const params = {
        pageNo: 1,
        pageSize: 100,
        dictType: 'countryside_resident_label'
    }
    globalApi.getDictData(params).then((res) => {
        optionlabel.value = []
        res.list.forEach((item) => {
            optionlabel.value.push({
                label: item.label,
                value: item.value,
                selected: false
            })
        })
    })
}
/** 选项卡颜色 */
const colorbtn = (index) => {
    //   optionlabel.value[index].selected = !optionlabel.value[index].selected;
}
/** 取消按钮操作 */
const gridCancel = () => {
    visible.value = false
    emit('getexamineShow', visible.value)
    emit('geteditData', props.editData.pageNo)
}
/** 确定按钮操作 */
const gridSure = () => {
    const ResidentinfoData = {
        auditResult: JSON.parse(formData.result),
        auditComment: formData.situation,
        id: props.editData.id
    }
    if (formData.result === 'true') {
        formData.situation = ''
        ElMessageBox.confirm(
            '是否确认通过审核?',
            '提示',
            {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            }
        )
            .then(() => {
                getgridApi.getResidentInfo(ResidentinfoData).then((res) => {
                    if (res) {
                        ElMessage.success('审核通过！')
                        visible.value = false
                        emit('getexamineShow', visible.value)
                        emit('geteditData', props.editData.pageNo)
                    }
                })
            })
            .catch(() => {
                ElMessage.info('已取消审核')
            })
        return
    }
    if (formData.result === 'false' && formData.situation && formData.situation.trim()) {

        ElMessageBox.confirm(
            '是否确认驳回审核?',
            '提示',
            {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            }
        )
            .then(() => {
                getgridApi.getResidentInfo(ResidentinfoData).then((res) => {
                    if (res) {
                        ElMessage.success('审核驳回成功！')
                        visible.value = false
                        emit('getexamineShow', visible.value)
                        emit('geteditData', props.editData.pageNo)
                    }
                })
            })
            .catch(() => {
                ElMessage.info('已取消审核')
            })

    } else {
        ElMessage.warning('驳回说明为必填项不能为空！')
    }
}
onMounted(() => {
    getresidentLabel()
})
</script>
<style scoped>
.grid_cont {
    min-height: 600px;
    background: #fff;
}

.grid_cont2 {
    width: 100%;
    background: #fff;
    height: 65px;
    justify-content: center;
    align-items: center;
    display: flex;
    padding: 0;
    box-shadow: 0px -2px 6px 0px rgba(188, 188, 188, 0.65);
}


.grid_btn {
    width: 80px;
    height: 30px;
}

.grid_btn:hover {
    opacity: 0.8;
}

.avatar-uploader .avatar {
    width: 178px;
    height: 178px;
    display: block;
}

::v-deep .avatar-uploader .el-upload {
    border: 1px solid var(--el-border-color);
    border-radius: 6px;
    position: relative;
    overflow: hidden;
    transition: var(--el-transition-duration-fast);
    cursor: not-allowed;
}

::v-deep .el-icon.avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 150px;
    height: 150px;
    text-align: center;
    cursor: not-allowed;
    background-color: var(--el-disabled-bg-color);
}

.inputstyle {
    width: 257px;
    height: 28px;
    line-height: 28px;
    color: var(--el-disabled-text-color);
    -webkit-text-fill-color: var(--el-disabled-text-color);
    cursor: not-allowed;
    background-color: var(--el-disabled-bg-color);
    box-shadow: 0 0 0 1px var(--el-disabled-border-color);
    border-radius: var(--el-input-border-radius, var(--el-border-radius-base));
    padding: 1px 11px;
    text-align: left;
}

.identity_style {
    min-width: 77px;
    height: 30px;
    line-height: 30px;
    text-align: center;
    border-radius: 5px;
    padding: 0 5px;
    margin: 0px 5px 10px 5px;
    font-size: 12px;
    border: none;
    cursor: pointer;
    user-select: none;
    background: #EFF0F0;
    border: 1px solid #EFF0F0;
    cursor: not-allowed;
    color: #888;
    font-weight: 550;
}

.selected {
    border: 1px solid rgba(16, 90, 215, 1);
    color: #437BC7;
    background: #F1F8FF;
}

.identity_style:hover {
    opacity: 0.8;
}
</style>